#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<algorithm>
using namespace std;

const int N = 1e6 + 10;
struct node
{
    int l, r;
}arr[N];
int n;

bool cmp(node& n1, node& n2)
{
    return n1.l < n2.l;
}

int main()
{
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> arr[i].l >> arr[i].r;
    sort(arr + 1, arr + 1 + n, cmp);
    int ret = 1;
    int r = arr[1].r;
    for (int i = 2; i <= n; i++)
    {
        if (arr[i].l < r)
            r = min(r, arr[i].r);
        else
            ret++, r = arr[i].r;
    }
    cout << ret << endl;
    return 0;
}